import { BrowserTab } from '@ionic-native/browser-tab';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { Component } from '@angular/core';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
import { NavController,Platform } from 'ionic-angular';
import { HttpService } from './../../helper/http';


@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers:[HttpService,BarcodeScanner,InAppBrowser,BrowserTab]
})
export class HomePage {
  api:any;
  scanresult:string="";
  otherResult:string="";
  pageOrForm:boolean;
  constructor(public navCtrl: NavController,
  public hs:HttpService,
  public platform:Platform,
  public bs:BarcodeScanner,
  private iab: InAppBrowser,
  private bt: BrowserTab) {

  }
  load(){
    this.hs.get('http://192.168.2.130:8091/dashboard/CurrentWeekPeriod').then(data=>{
      this.api=data;
      console.log(this.api);
    })
  }
  scan(){
    this.platform.ready().then(()=>{
      this.bs.scan().then((barcodeData) => {
        this.scanresult=barcodeData.text;
      }, (err) => {
        this.scanresult=err;
      });
    });
  }
  showWebIab(){
    console.log("ceshi");
    let ps=this.pageOrForm?"pagesheet":"formsheet";
    const browser = this.iab.create('http://dev.b2c3.tiens.com','_self',"presentationstyle="+ps+",toolbarposition=top");
    browser.show();
    // browser.executeScript(...);
    // browser.insertCSS(...);
    // browser.close();
  }
  showWebBT(){
    this.bt.isAvailable()
    .then((isAvailable: boolean) => {

      if (isAvailable) {

        this.bt.openUrl('http://dev.b2c3.tiens.com');

      } else {

        // open URL with InAppBrowser instead or SafariViewController

      }

    },(err)=>{
        this.otherResult=err;
    });
  }
}
